<template>
	<compWrapper v-if="hasWrapper" :title="$t('global.common.operate_history')" theme="gray">
		<slot></slot>
		<Table class="margin-15" :columns="getColumns" :data="getData" :loading="loading" border></Table>
		<slot name="footer" slot="footer"></slot>
	</compWrapper>
	<Table
		v-else
		class="margin-15"
		:columns="getColumns"
		:data="getData"
		:loading="loading"
		border
	></Table>
</template>
<script>

export default {
	props: {
		// 'data', 'wrapper', 'ajaxRequest', 'params',
		data: Array,
		columns: Array,
		wrapper: Boolean,
		ajaxRequest: Function,
		params: Object,
		opActionMap: Object
	},
	components: {
		compWrapper: () => import("./wrapper"),
	},
	data() {
		return {
			dataList: [],
			loading: false,
		}
	},
	created() {
		this.getLogList();
	},
	methods: {
		getLogList() {
			if (typeof this.ajaxRequest === 'function') {
				this.loading = true;
				this.ajaxRequest(this.params).then(res => {
					this.loading = false;
					this.dataList = res.data || [];
				}, err => {
					this.loading = false;
					this.$Message.error(err.message);
				})
			}
		},
	},
	computed: {
		// log 类型转换
		getLogActionMap() {
			return this.opActionMap || {
				'10': "推送附件",
				'13': "库存流水回写",
				'90': "失效",
				'100': "创建",
				'200': "更新",
				'210': "提交",
				'230': "保存并提交",
				'240': "撤回申请",
				'250': "保存",
				'260': "编辑",
				'290': "卸货",
				'300': "删除",
				'400': "取消",
				'500': "审核通过",
				'600': "审核拒绝",
				'610': "BOSS处理",
				'710': "已出库",
				'720': "确认",
				'800': "已完成",
				'830': "生成箱标",
				'930': "推送仓库",
				'1010': "调拨入库执行单回传boss"
			}
		},
		hasWrapper() {
			return this.wrapper || this.$slots.footer || this.$slots.default;
		},
		getData() {
			return this.data || this.dataList
		},
		getColumns() {
			if (this.columns && this.columns.length > 0) return this.columns;
			return [{
				title: this.$ct('global.common.operate_time'),
            	key: 'createdAt',

			}, {
			    title: this.$ct('global.common.operator'),
                key: 'createdName',
			}, {
				title: this.$ct('global.common.operate_note'),
                key: 'opAction',
                render: (h, { row }) => {
                    const remark = row.opRemark || row.remark || row.opResult;
//                    const value = row.opAction || row.operateType;
//                    return this.getLogActionMap[value] || value + '：' + remark;
                    return remark;
                },
			}];
		}
	}
}
</script>
